<template>
  <!-- 勤工助学岗 -->
  <div class="app-container">
    <div class="Information" v-for="(item, i) in form" :key="i">
      <el-row>
        <el-form model="form">
          <el-col :span="9">
            <el-form-item label="用工部门:">{{ item.deptName }} </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="岗位名称:">{{ item.postName }} </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="用工时长:">{{ item.workHours }}小时 </el-form-item>
          </el-col>

          <el-col :span="3">
            <el-form-item label="岗位薪酬:">{{ item.postComp }}元/小时 </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="注册需求人数:"
              >{{ item.postReqCount }}
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="岗位描述:">{{ item.postDesc }} </el-form-item>
          </el-col>
          <el-col :span="8" style="text-align: right">
            <el-button
              type="primary"
              :style="{
                'background-color':
                  item.applyType == '1' || item.postStatus != '正常'
                    ? '#bebebe'
                    : '#54bcbd',
              }"
              @click="handleApply(item)"
              :disabled="
                item.applyType == '1' || item.postStatus != '正常'
                  ? true
                  : false
              "
              v-hasPermi="['wsp:postemp:apply']"
              >{{ item.applyType == "1" ? "已申请" : "申请" }}</el-button
            >
          </el-col>
        </el-form>
      </el-row>

      <div style="position: absolute; top: 0; right: 0px">
        <el-button size="mini" v-if="item.applyStatus">{{
          item.applyStatus
        }}</el-button>
        <el-button
          size="mini"
          type="primary"
          style="background-color: #e99d42"
          >{{ item.postStatus }}</el-button
        >
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 申请岗位对话框 -->
    <el-dialog
      title="申请"
      :visible.sync="open"
      width="60%"
      append-to-body
      @close="cancel"
      destroy-on-close
    >
      <el-form ref="form" v-model="formAdd" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用工部门:"
              >{{ formAdd.deptName }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗位名称:">{{
              formAdd.postName
            }}</el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用工时长:">{{
              formAdd.workHours
            }}天</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位薪酬:">{{
              formAdd.postComp
            }}元/小时</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位需求人数:">{{
              formAdd.postReqCount
            }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="岗位描述:">{{
              formAdd.postDesc
            }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="类型" prop="povertyType">
              <el-select
                v-model="formAdd.povertyType"
                clearable
                placeholder="请选择贫困类型"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.wsp_poverty_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开户银行" prop="bankName">
              <el-input
                v-model.trim="formAdd.bankName"
                placeholder="请输入开户银行"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="银行卡号" prop="cardNumber">
              <el-input
                v-model.trim="formAdd.cardNumber"
                placeholder="请输入银行卡号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="申请理由:" prop="applyReason">
              <el-input
                type="textarea"
                v-model.trim="formAdd.applyReason"
                placeholder="请输入申请理由"
              ></el-input>
              <!-- <el-input v-model="regCode" placeholder="请输入学生注册号" type="textarea" maxlength="50"
                                :autosize="{ minRows: 2, maxRows: 4 }" show-word-limit /> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
    
<script>
import { wsplist, apply } from "@/api/worStudy/workHard";
export default {
  name: "Dict",
  dicts: ["psy_cons_req_type", "wsp_poverty_type"],
  data() {
    return {
      form: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      formAdd: {
        applyReason: "",
        povertyType: "",
      },
      FormData: {},
      open: false,
      total: 0,
      rules: {
        povertyType: [
          { required: true, message: "请选择类型", trigger: "change" },
        ],
        applyReason: [
          { required: true, message: "请填写申请理由", trigger: "blur" },
        ],
        bankName: [
          { required: true, message: "请输入开户银行", trigger: "blur" },
        ],
        cardNumber: [
          { required: true, message: "请输入银行卡号", trigger: "blur" },
        ],
      },
    };
  },
  created() {},
  mounted() {},
  methods: {
    handleApply(data) {
      this.open = true;
      this.formAdd = data;
    },
    getList(data) {
      if (data.page || data.limit) {
        data.pageNum = data.page;
        data.pageSize = data.limit;
      }
      wsplist(data).then((res) => {
        this.form = res.rows;
        this.form.forEach((item) => {
          if (item.postStatus == "Y") {
            item.postStatus = "正常";
          } else if (item.postStatus == "N") {
            item.postStatus = "招满";
          } else if (item.postStatus == "JS") {
            item.postStatus = "用工结束";
          }
          if (item.applyStatus == "D") {
            item.applyStatus = "待审核";
          } else if (item.applyStatus == "Y") {
            item.applyStatus = "审核通过";
          } else if (item.applyStatus == "N") {
            item.applyStatus = "审核不通过";
          } else if (item.applyStatus == "JS") {
            item.applyStatus = "用工结束";
          }
        });
        this.total = res.total;
        console.log(res, "查询勤工助学岗列表");
      });
    },
    cancel() {
      this.open = false;
      this.formAdd = {};
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          apply(this.formAdd).then((response) => {
            console.log(response, "申请");
            if (response.code == 200) {
              this.$modal.msgSuccess("申请成功");
              this.open = false;
              this.getList(this.queryParams);
            }
          });
        }
      });
    },
  },
};
</script>
<style scoped>
.Information {
  background-color: #efefef;
  margin-bottom: 2%;
  padding: 1% 2% 0 2%;
  position: relative;
}
</style>
